package com.zlq.cn.admin.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zlq.cn.admin.domain.Role;
import com.zlq.cn.admin.service.RoleService;
import com.zlq.cn.api.SignApiResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.ServletRequest;

@Api(tags = "角色")
@RestController
@RequestMapping("/api/role")
public class RoleController {

    @Resource
    private RoleService roleService;

    @ApiOperation("角色列表")
    @PostMapping("/list")
    public SignApiResult<Page> list(ServletRequest request, Page page, String name) {
        roleService.getList(page, name);
        return SignApiResult.resultSuccess(page);
    }

    @ApiOperation("角色删除")
    @PostMapping("/delete")
    public SignApiResult<Boolean> delete(Integer id) {
        roleService.delete(id);
        return SignApiResult.resultSuccess(true);
    }

    @ApiOperation("角色新增")
    @PostMapping("/save")
    public SignApiResult<Boolean> save(Role role) {
        roleService.save(role);
        return SignApiResult.resultSuccess(true);
    }
}
